<?php
use app\modules\cruise\models\Customer;
use app\modules\cruise\models\RoomCode;
use app\modules\cruise\models\RoomUse;
use yii\helpers\Html;

$this->title = '人员统计';

?>
<style type="text/css">
	.btn-info.active{background-color: #ef9f1a;border-color: #ef9f1a;}
</style>

<div class="room-use-index">

	<div class="col-md-12" style="margin-bottom: 20px;">

		 <?= Html::a('房间使用统计', ['index','act'=>'room'], ['class' => ($act == 'room') ? 'btn btn-info active' : 'btn btn-info' ]) ?>
		 <?= Html::a('人员签到统计', ['index','act'=>'people'], ['class' => ($act == 'people') ? 'btn btn-info active' : 'btn btn-info' ]) ?>
		 <?= Html::a('团队签到统计', ['index','act'=>'group'], ['class' => ($act == 'group') ? 'btn btn-info active' : 'btn btn-info']) ?>
		 <?= Html::a('体系签到统计', ['index','act'=>'supply'], ['class' => ($act == 'supply') ? 'btn btn-info active' : 'btn btn-info']) ?>
	</div>

	<?php

	if($act == 'room'){
             //房间使用
            $room = RoomUse::find()->select('*,COUNT(*) AS num_s')->where(['status'=>1])->groupBy(['room_id','num'])->all();
            $room_num = RoomUse::find()->where(['status'=>1])->count();

            //总人数
            $customer_num = 0;
            $room_use = RoomUse::find()->where(['status'=>1])->all();
            if($room_use){
                foreach($room_use as $ru){
                    $customer_num += $ru->customerNums;
                }
            }
      echo  $this->render('room',['room'=>$room,'room_num'=>$room_num,'customer_num'=>$customer_num]);     
    }else if($act == 'people'){
            //人员签到
            //所有人员
            $all_people = Customer::find()->where(['status'=>1])->count();

            //已签到
            $sign = Customer::find()->where(['sign'=>1,'status'=>1])->andWhere(['<','cancel',3])->count();
            //未签到
            $un_sign = Customer::find()->where(['sign'=>0,'status'=>1])->andWhere(['<','cancel',3])->count();
            //已取消
            $cancel = Customer::find()->where(['status'=>1])->andWhere(['=','cancel',3])->count();
       echo  $this->render('people',['all_people'=>$all_people,'sign'=>$sign,'un_sign'=>$un_sign,'cancel'=>$cancel]);   
    }else if($act == 'group'){
        $group_arr = [];
        $model = Customer::find()->where(['status'=>1])->groupBy(['group'])->all();
        if($model){
          foreach($model as $c){
               if($c->group){
                 $group_arr[$c->id] = $c->group;
               }
          } 
        }
        sort($group_arr);

        //$group_people = Customer::find()->select('*,COUNT(*) AS num_s')->where(['status'=>1])->groupBy(['group'])->orderBy(['group'=>SORT_DESC])->all();
        //var_dump($group_people);
        //exit();
        echo  $this->render('group',['group_arr'=>$group_arr]);   
   }else if($act == 'supply'){
            
        $supply_people = Customer::find()->select('*,COUNT(*) AS num_s')->where(['status'=>1])->groupBy(['supply'])->all();

        echo  $this->render('supply',['supply_people'=>$supply_people]);
   }

   ?>

	
</div>
